package com.hp.attendance.serlvet.attendance;

import com.hp.attendance.entity.Attendance;
import com.hp.attendance.service.AttendanceService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.time.LocalDateTime;

@WebServlet("/addEnd")
public class addEndServlet extends HttpServlet {

    private AttendanceService attendanceService=new AttendanceService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String employee_number = req.getParameter("employee_number");
        //获取当前时间
        LocalDateTime now = LocalDateTime.now();
        int hour = now.getHour();
        int minute = now.getMinute();
        int second = now.getSecond();
        Attendance att = new Attendance();
        if (hour>=18){
            att.setEnd_type("正常");
        }else {
            att.setEnd_type("早退");
        }
        att.setEnd_time(hour+":"+minute+":"+second);
        att.setEmployee_number(Integer.valueOf(employee_number));
        try {
            attendanceService.addEndAttend(att);
            req.getRequestDispatcher("/welcome").forward(req,resp);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }
}
